#ifndef CONNECTION_H_INCLUDED
#define CONNECTION_H_INCLUDED

#include "protocol.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <pthread.h>
#include <unistd.h>

#define PORT 8852
#define MAXBOARDS 15
#define MAXMEMBERS 15

class WaitingRoom;
class board;

class Connection {
public:
    Connection();
    bool init(char*, char*, int);
    ~Connection();
    void startReading();
    void addWaitingRoom(WaitingRoom*);
    void join(int);
    void leave(int);
    friend void *parseInput(void*);
    void sendMove(CODE cmd, int room);
    void addBoard(board*);
    void removeBoard(board*);

private:
    int sockfd;
    bool connected;
    int inRoom;
	pthread_t thread;
	WaitingRoom* roomList;
    Player* p[MAXMEMBERS];
	Room* rm[MAXMEMBERS];
	board* boardArray[MAXBOARDS];

	/* Functions */
	board* getBoard(int);
	Player* getPlayer(int);
	int readRoom();
	int readPlayer();
	bool checkIfInRoom(int);
	//void storeMove(int mv);
	//void hastMoves(int r);
	int getPlayerRepr(int);
};
#endif // CONNECTION_H_INCLUDED

void *parseInput(void*);
